import sys
import time
from PyQt5.QtWidgets import QApplication, QSplashScreen, QMainWindow
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("主窗口")
        self.setGeometry(300, 300, 400, 300)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    # 加载启动画面的图片
    pixmap = QPixmap('../picture/splash.png')
    # splash = QSplashScreen(pixmap, Qt.WindowStaysOnTopHint)
    splash = QSplashScreen()
    # 显示启动画面
    splash.show()

    # 模拟加载过程
    for i in range(100):
        # 更新启动画面上的消息
        splash.showMessage(f"正在加载: {i + 1}%", Qt.AlignBottom | Qt.AlignHCenter)
        app.processEvents()
        time.sleep(0.05)

    # 创建并显示主窗口
    main_window = MainWindow()
    main_window.show()

    #关闭启动画面
    splash.finish(main_window)

    sys.exit(app.exec_())